package com.mycompany.webapp.controller.Almacen;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;

import com.mycompany.domain.Almacen;
import com.mycompany.service.AlmacenService;

@Controller
@RequestMapping("/almacen/**")
public class AlmacenController {
	
	@Autowired
	private AlmacenService almacenService;
	
	@RequestMapping(value="/almacenlist.html")
	public void listarAlmacenes(Model model){
		List<Almacen> almacenes=almacenService.obtenerAlmacenes();
		model.addAttribute("almacenes",almacenes);
	}
	
	@RequestMapping(value="/almacenForm.html", method=RequestMethod.POST)
	public String guardarAlmacen(@ModelAttribute("almacen") Almacen almacen,
			BindingResult result, SessionStatus status, HttpServletRequest request, Model model){
		
		almacenService.guardarAlmacen(almacen);
		
		return "/almacen/almacenform";
	}
}
